package com.solution.admin.promotion.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.solution.admin.promotion.dao.PromotionTargetDao;
import com.solution.admin.promotion.entity.PromotionTargetEntity;
import com.solution.admin.promotion.service.PromotionTargetService;
import com.solution.common.dao.BaseDao;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;
import com.solution.common.service.impl.BaseServiceImpl;

/**
 * 活动对象信息service实现层
 * 
 * @author xu_cc
 * @date 2017-09-27 23:25:28
 */
@Service
public class PromotionTargetServiceImpl extends BaseServiceImpl<PromotionTargetEntity> implements PromotionTargetService {

    /**
     * 活动对象信息接口
     */
    @Autowired
    private PromotionTargetDao promotionTargetDao;

    protected BaseDao<PromotionTargetEntity> getDao() {
        return this.promotionTargetDao;
    }

    /**
     * 保存活动对象信息
     * 
     * @param promotionTargetEntity
     *            活动对象信息实体
     * @return Long 添加成功活动对象信息的ID
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    public long savePromotionTarget(PromotionTargetEntity promotionTargetEntity) {
        return promotionTargetDao.savePromotionTarget(promotionTargetEntity);
    }

    /**
     * 分页查询活动对象信息
     * 
     * @param pageParam
     *            分页参数
     * @param paramMap
     *            查询参数
     * @return PageBean 分页参数和分页数据
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    @Override
    public PageBean listPromotionTargetPage(PageParam pageParam, Map<String, Object> paramMap) {
        return promotionTargetDao.listPromotionTargetPage(pageParam, paramMap);
    }

    /**
     * 根据ID查询用户信息
     * 
     * @param id
     *            用户id
     * @return promotionTargetEntity 用户对象
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    public PromotionTargetEntity getPromotionTargetById(Long id) {
        return promotionTargetDao.getById(id.longValue());
    }

    /**
     * 更新用户
     * 
     * @param promotionTargetEntity
     *            用户实体
     * @return Long 更新是否成功，>1代表更新成功
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    @Override
    public int updatePromotionTarget(PromotionTargetEntity promotionTargetEntity) {
        return promotionTargetDao.updatePromotionTarget(promotionTargetEntity);
    }

    /**
     * 根据条件查询活动对象信息
     * 
     * @param param
     * @return 数据列表
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    @Override
    public List<PromotionTargetEntity> listPromotionTarget(Map<String, Object> param) {
        return promotionTargetDao.listPromotionTarget(param);
    }

    /**
     * 删除活动对象信息
     * 
     * @param
     * @return int 返回删除记录条数
     * @author xu_cc
     * @date 2017-09-27 23:25:28
     */
    public int deletePromotionTargetById(long id) {
        return promotionTargetDao.deleteById(id);
    }
    
    /**
     * 查询当前客户是否属于指定活动的活动对象
     * @param param
     * @return
     */
	public boolean existsInPromotionTarget(Map<String, Object> param){
		// 查询客户的扩展属性是否符合商品活动定义的参与对象
		List<PromotionTargetEntity> pteList = promotionTargetDao.listPromotionTargetForShoppingCheckOut(param);
		return (pteList != null && pteList.size() > 0)? true : false;
	}

}
